//
//  UserInfoModel.m
//  ShowYork
//
//  Created by hxh on 2020/8/27.
//  Copyright © 2020 hxh. All rights reserved.
//


#import "UserInfoModel.h"

@implementation UserInfoModel
MJCodingImplementation
- (void)save{
    NSMutableData *data = [NSMutableData data];
    //创建归档对象
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
    //开始归档
    [archiver encodeObject:self forKey:@"CLUserInfo"];
    //完成归档
    [archiver finishEncoding];
    //写入文件当中
    
    BOOL result = [data writeToFile:RPArchiverPath atomically:YES];
    if (result) {
        NSLog(@"归档成功:%@",RPArchiverPath);
    }else
    {
        NSLog(@"归档不成功!!!");
    }
}
+(UserInfoModel *)userInfo{
    //准备解档路径
    NSData *myData = [NSData dataWithContentsOfFile:RPArchiverPath];
    //创建反归档对象
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:myData];
    //反归档
    UserInfoModel *userInfo = [UserInfoModel new];
    userInfo = [unarchiver decodeObjectForKey:@"CLUserInfo"];
    //完成反归档
    [unarchiver finishDecoding];
    
    return userInfo;
}

+ (void)deleteUserInfo{
    
    NSFileManager *fileManger = [NSFileManager defaultManager];
   
    [fileManger removeItemAtPath:RPArchiverPath error:nil];
}
- (NSString *)levelStr{
    if (self.userLevel.intValue == 13) {
        return @"高三";
    }
    if (self.userLevel.intValue == 12) {
        return @"高二";
    }
    if (self.userLevel.intValue == 11) {
        return @"高一";
    }
    return @"未设置";
}

@end
